package com.example.dropoff;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.TextView;


public class DetailActivity extends Activity
{
	String TAG = "test";
   	private DbOpenHelper mDbOpenHelper;
	private Cursor mCursor;
	private InfoClass mInfoClass;
	private ArrayList<InfoClass> mInfoArray;
	TextView name, amount, unit, limit;

	Intent intent;
    
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_detail);
      
       name = (TextView)findViewById(R.id.name);
       amount = (TextView)findViewById(R.id.amount);
       unit = (TextView)findViewById(R.id.unit);
       limit = (TextView)findViewById(R.id.limit);
       
       // DB Create and Open
       mDbOpenHelper = new DbOpenHelper(this);
       mDbOpenHelper.open();
        
    
              
//       startManagingCursor(mCursor);
        
        
       mInfoArray = new ArrayList<InfoClass>();
       
 
       doWhileCursorToArray();
       
       for(InfoClass i : mInfoArray){
       	DLog.d(TAG, "ID = " + i._id);
       	DLog.d(TAG, "NAME= : " + i.name);
       	DLog.d(TAG, "DATE_YY = :" + i.date_yy);
       	DLog.d(TAG, "DATE_DD = :" + i.date_dd);
       	DLog.d(TAG, "DATE_MM = :" + i.date_mm);
       	DLog.d(TAG, "AMOUNT = " + i.amount);
    	DLog.d(TAG, "UNIT =  :" + i.unit);
    	DLog.d(TAG, "MEMO =  :" + i.memo);
       }
       
      //////////////////////////////////////////////////////////////
       // 위젯 레퍼런스 시작
        
        }
   
   protected void onDestroy() {
   	mDbOpenHelper.close();
   	super.onDestroy();
   }
   
	public void doWhileCursorToArray()
	{

		mCursor = mDbOpenHelper.getColumn(1);
		intent = getIntent();
		intent.getIntExtra("_id", 1);		
		
		mInfoClass = new InfoClass(
				mCursor.getInt(mCursor.getColumnIndex("_id")),
				mCursor.getString(mCursor.getColumnIndex("name")),
				mCursor.getString(mCursor.getColumnIndex("date_yy")),
				mCursor.getString(mCursor.getColumnIndex("date_mm")),
				mCursor.getString(mCursor.getColumnIndex("date_dd")),
				mCursor.getString(mCursor.getColumnIndex("amount")),
				mCursor.getString(mCursor.getColumnIndex("unit")),
				mCursor.getString(mCursor.getColumnIndex("memo"))
				);

		Log.d("dd",	intent.getIntExtra("_id", 1)+"");
		Log.d("dd",	mInfoClass.name);
		Log.d("dd",	mInfoClass.amount);
		Log.d("dd",	mInfoClass.unit);
		Log.d("dd",	mInfoClass.date_yy);
		Log.d("dd",	mInfoClass.date_mm);
		Log.d("dd",	mInfoClass.date_dd);
		
		
		
		name.setText(mInfoClass.name);
		amount.setText(mInfoClass.amount);
		unit.setText(mInfoClass.unit);
		limit.setText(mInfoClass.date_yy + ". " + mInfoClass.date_mm + ". " + mInfoClass.date_dd);
	   
		mInfoArray.add(mInfoClass);
		mCursor.close();
	}
   @Override

   protected void onResume(){
	    super.onResume();
	    	
	    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
	}
}